<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html >
 <%@include file="./resource/head.jsp" %> 
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <title>创建游戏</title>
    <!-- Tell the browser to be responsive to screen width -->
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">

  </head>
  <body ng-app="app" class=" werewolf" ng-controller="game">
  	<nav class="navbar navbar-default">
	    <div class="navbar-header">
	      <a class="navbar-brand" href="#">
	        <img alt="狼人杀" src="">
	      </a>
	    </div>
	</nav>
	
  <div class="container">
	<page class="row active" id="config">
				<addgame class="col-xs-12 form-horizontal">
			  		<!-- 名称 -->
			  		<label for="config">配置</label>
			  		<div class="form-group">
						<label class="col-xs-2 control-label">狼人</label>
						<div class="col-xs-10">
							<input type="number" class="form-control" placeholder="狼人数量..." id="wolf" ng-model="wolf">	
						</div>
					</div>
			  		<div class="form-group">
						<label class="col-xs-2 control-label">平民</label>
						<div class="col-xs-10">
							<input type="number" class="form-control" placeholder="平民数量..." id="citizen" ng-model="citizen">
						</div>
					</div>
			  		<div class="form-group">
						<label class="col-xs-3 control-label">预言家</label>
						<div class="col-xs-1">
							<input type="checkbox" class="checkbox" id="foresee" ng-model="forsee">
						</div>
						
						<label class="col-xs-3 control-label">猎人</label>
						<div class="col-xs-1">
							<input type="checkbox" class="checkbox" id="hunter" ng-model="hunter">
						</div>
						<label class="col-xs-3 control-label">女巫</label>
						<div class="col-xs-1">
							<input type="checkbox" class="checkbox" id="witch" ng-model="witch">
						</div>
					</div>
					<div class="form-group">
						<label class="col-xs-3 control-label">守卫</label>
						<div class="col-xs-1">
							<input type="checkbox" class="checkbox" id="guard" ng-model="guard">
						</div>
						<label class="col-xs-3 control-label">白痴</label>
						<div class="col-xs-1">
							<input type="checkbox" class="checkbox" id="idiot" ng-model="idiot">
						</div>
					</div>
					<!-- 提交 -->		
			  		<div class="form-group">	
			  			<div class="col-xs-offset-2 col-xs-10">
			  				<button class="btn btn-primary" ng-click="add()">创建游戏</button>
			  			</div>	
			  		</div>
				</addgame>
	  	</page>
	  	<div class="row">
	  		<div class="col-xs-12">
		  		<table class="table">
		  			<tr ng-repeat="game in gamelist">
		  				<td>{{game.name}}</td>
		  				<td>
		  					<button class="btn btn-danger" ng-click="reset(game)">重置</button>
		  					<button class="btn btn-danger" ng-click="del(game)">删除</button>
		  				</td>
		  			</tr>
		  		</table>
	  		</div>
	  	</div>
	</div>
  </body>
  <%@include file="./resource/foot.jsp" %>  
  <script>
  var module=angular.module("app",[]);
  var gameList=module.controller("game",function($scope,$http){
	  $scope.forsee=true;
	  $scope.witch=true;
	  $http({
		  method:'post',
		  url: '/werewolf/admin/gamelist'
	  }).success(function(data){
		 $scope.gamelist=data.gamelist; 
	  });
	  $scope.add=function(){
		  $http({
			  method:'post',
			  url: '/werewolf/admin/addgame',
			  data:{
				  'wolfnumber':$scope.wolf,
				  'citizennumber':$scope.citizen,
				  'forsee':$scope.forsee,
				  'hunter':$scope.hunter,
				  'witch':$scope.witch,
				  'guard':$scope.guard,
				  'idiot':$scope.idiot
			  }
		  }).success(function(data){
			 $scope.gamelist=data.gamelist; 
		  });
	  }
	  $scope.reset=function(game){
		  $http({
			  method:'post',
			  url:'/werewolf/admin/reset',
			  data:game
		  }).success(function(data){
			  alert("重置成功！");
			  $scope.gamelist=data.gamelist;
		  })
	  }

	  $scope.del=function(game){
		  $http({
			  method:'post',
			  url:'/werewolf/admin/delete',
			  data:game
		  }).success(function(data){
			  $scope.gamelist=data.gamelist;
		  })
	  }
  });
  
  </script>
</html>
